<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>message</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link href="../../css/app.css" rel="stylesheet" />
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/jquery-1.12.4.min.js"></script>
		<script src="../../js/app.js"></script>
		<style>
		.circle { 
                position: fixed; 
                text-align: center; 
                margin-right: calc((20% - 65px)/2); 
                right: 0;
                bottom: 18px; 
                width: 65px; 
                height: 65px;
                padding:20px;                
                border-radius: 50px; 
                background: rgba(100, 177, 245, 0.8); 
                z-index: 99; 
        } 
			
			
		</style>
		
	</head>  

	<body>
		<header class="mui-bar mui-bar-nav app-main-background-color" >
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">密码修改</h1>
		</header>
		<div class="mui-content">
		<div id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>原密码</label>
					<input id='LOGIN_PASS' type="password" class="mui-input-clear mui-input" placeholder="请输入密码" value="">
				</div>
				<div class="mui-input-row">
					<label>新密码</label>
					<input id='LOGIN_PASS_NEW' type="password" class="mui-input-clear mui-input" placeholder="请输入密码" value="">
				</div>
				<div class="mui-input-row">
					<label>确认密码</label>
					<input id='LOGIN_PASS_NEW_CH' type="password" class="mui-input-clear mui-input" placeholder="请输入确认密码" value="">
				</div>
			<div class="mui-content-padded">
				<button id='changePass' class="mui-btn mui-btn-block mui-btn-primary">修改</button>

			</div>
			
			</div>
	</div>

		<script type="text/javascript">

				var loginButton = document.getElementById('changePass');
				loginButton.addEventListener('tap', function(event) {
						
						var loginPassNew = document.getElementById('LOGIN_PASS_NEW').value;
						var loginPassNewCH = document.getElementById('LOGIN_PASS_NEW_CH').value;
						if(loginPassNew != loginPassNewCH){
							plus.nativeUI.toast("新密码输入不正确");
							return false;
						}
						
						var user = JSON.parse(localStorage.getItem('user') || '{}');
						var loginInfo = {
							LOGIN_NAME: user.LOGIN_NAME,
							LOGIN_PASS: document.getElementById('LOGIN_PASS').value,
							LOGIN_PASS_NEW: loginPassNew,
							TOKEN: user.TOKEN
						};
						
						
		console.log("调用到方法----------------------------------");  
		callback = callback || mui.noop;

		if (loginInfo.LOGIN_NAME == "") {
			return callback('账号不能为空');
		}
		if (loginInfo.LOGIN_PASS == "") { 
			return callback('密码不能为空');
		}
		var loginUrl = app.SERVER_URL + "/mobile/changepass"; 

		jQuery.ajax({
						url:loginUrl,
						data: loginInfo,						
						contentType: "application/x-www-form-urlencoded",
						dataType:'json',//服务器返回json格式数据
						type:'post',//HTTP请求类型 
						success:function(data){
							var resultCode = data.RESULT_CODE;
							var resultInfo = data.RESULT_INFO;
							document.getElementById('LOGIN_PASS').value = '';
							document.getElementById('LOGIN_PASS_NEW').value = '';
							document.getElementById('LOGIN_PASS_NEW_CH').value = '';
							return callback(resultInfo);
						},
						error:function(xhr,type,errorThrown){  
							//异常处理；  
							console.log(type); 
							console.log(JSON.stringify(errorThrown)); 
							console.log(JSON.stringify(xhr)); 
							
							return callback('密码修改异常，请重试！错误详情：'+type);
						}
					});
					event.preventDefault();
					});
			
			function callback(err) {
							if (err) {
								plus.nativeUI.toast(err);
								return;
							}
						}
	function change_pass(loginInfo, callback) {
		console.log("调用到方法----------------------------------");  
		callback = callback || mui.noop;

		if (loginInfo.LOGIN_NAME == "") {
			return callback('账号不能为空');
		}
		if (loginInfo.LOGIN_PASS == "") { 
			return callback('密码不能为空');
		}
		var loginUrl = app.SERVER_URL + "/mobile/changepass"; 
		console.log(loginUrl);
		console.log(JSON.stringify(loginInfo));
		$.ajax(loginUrl,{
						data: loginInfo,	
						contentType: "application/x-www-form-urlencoded",
						dataType:'json',//服务器返回json格式数据
						type:'post',//HTTP请求类型 
						timeout:100000,//超时时间设置为100秒； 
						success:function(data){
							var resultCode = data.RESULT_CODE;
							var resultInfo = data.RESULT_INFO;
							console.log(data);
							return callback(resultInfo);
						},
						error:function(xhr,type,errorThrown){  
							//异常处理；  
							console.log(type); 
							console.log(JSON.stringify(errorThrown)); 
							console.log(JSON.stringify(xhr)); 
							
							return callback('密码修改异常，请重试！错误详情：'+type);
						}
					});
	   
	}; 
			
		</script>
	</body>

</html>    